#ifndef __SERVER_H__
#define __SERVER_H__

#include <soar.h>

__BEGIN_DECLS

/*----- 配置信息 -----*/
struct cnfg_info
{/*{{{*/
    char server[NAME_SIZE+1];
    unsigned int workers;
    struct
    {
        char location[LONG_FILE_NM_SIZE+1];
        unsigned int tracking;
    } _errlog_;
    struct
    {
        unsigned int server_port;
        unsigned int monitor_port;
    } _access_;
    struct
    {
        char user[NAME_SIZE+1];
        char passwd[PASSWD_ENC_SIZE+1];
        char database[NAME_SIZE+1];
        char host[NAME_SIZE+1];
        MYSQLC *db;
        //ORAPROC *db;
    } _db_;
};/*}}}*/
extern struct cnfg_info cnfg_info;

/*----- 统计信息 -----*/
struct stat_info
{/*{{{*/
    struct
    {/*{{{*/
        pthread_mutex_t lock;
        struct _worker_info
        {
            struct _client_info
            {
                char *ip;
                unsigned int port;
                unsigned int call_num;
            } client[EP_POLL_MAX_NUM];
            int client_num;
        } *worker;
    }/*}}}*/
    _worker_;

    struct
    {/*{{{*/
        pthread_mutex_t lock;
        struct _svc_info
        {
            char *name;
            unsigned int call_num;
        } *svc;
    }/*}}}*/
    _svc_;
};/*}}}*/
extern struct stat_info stat_info;

/*----- 操作信息 -----*/
enum thrd_state { THRD_RUNNING, THRD_SHUTDOWN };
struct operate_info
{/*{{{*/
    struct
    {
        pthread_mutex_t lock;
        unsigned int quit;
        enum thrd_state state;
    }
    _listener_;

    struct
    {
        pthread_mutex_t lock;
        unsigned int quit;
        enum thrd_state *state;
    }
    _worker_;
};/*}}}*/
extern struct operate_info operate_info;

/*----- 服务 -----*/
typedef int (*P_SVC_FUNC)(int, char *, char *);
#define SVC_FUNC(svc)   \
int SVC_FUNC_##svc(int worker_idx, char *request, char *respond)
struct svc_map
{/*{{{*/
    char *name;
    P_SVC_FUNC pfunc;
};/*}}}*/
extern struct svc_map SVC_MAP[];
extern unsigned int SVC_MAP_SIZE;

/*--- 错误码 ---*/
#define ERR_OK                      "0000"  /* 成功 */

#define ERR_SVC_INVALID             "1000"  /* 无效服务 */
#define ERR_SVC_NOT_FOUND           "1001"  /* 服务未存在 */

#define ERR_DB                      "9004"  /* 数据库错误 */
#define ERR_PARA                    "9006"  /* 参数错误 */

__END_DECLS

#endif
